﻿/*
 * @Description:用于回收站搜索
 */
var RecycleBinSearch = new Class({
    Autocomplete: function () {
        var txtEstateName = $("#txtEstateName"), hidEstateKeyId = $("#hidEstateKeyId"), txtBuildingName = $("#txtBuildingName"), hidBuildingKeyId = $("#hidBuildingKeyId"), txtHouseNo = $("#txtHouseNo"), hidHouseKeyId = $("#hidHouseKeyId");
        //楼盘自动完成及赋值隐藏域
        txtEstateName.change(function () {
            $(this).removeClass("checkError").next("span[class=wrong]").remove();
            hidEstateKeyId.val("");
            txtBuildingName.val("");
            hidBuildingKeyId.val("");
            txtHouseNo.val("");
           // btnHouseNoRegex.css("display", "none");
            hidHouseKeyId.val("");
            txtBuildingName.removeAttr("readonly");
            //txtBuildingName.attr("disabled", "disabled").removeClass("checkError").next("span[class=wrong]").remove();
            //txtHouseNo.attr("disabled", "disabled").removeClass("checkError").next("span[class=wrong]").remove();
            //if ($(this).next("span[class=wrong]").length <= 0 && !hidEstateKeyId.val() && other.trim(txtEstateName.val())) {
            //    //$(this).val(" ");
            //    $(this).addClass("checkError").after(agencyVerify.greatErrorHtml($(this), '楼盘名:必须从智能提示中选择！'));
            //}

        });
        txtEstateName.autocomplete(function () {
            return "/estate/estates-for-region-keyids-search-codition?EstateName=" + escape(txtEstateName.val()) + '&DistrictKeyId=' + $("#selDistrict").val() + '&RegionKeyId=' + $("#selRegion").val();
        }, {
            width: 260,
            max: 12,
            selectFirst: false,
            cacheLength: 0,
            formatItem: function (row) {
                return row.EstateFullName;
            },
            formatResult: function (row) {
                return row.EstateName;
            }
        }).result(function (a, b) {
            hidEstateKeyId.val(b.KeyId);

           
            txtBuildingName.removeAttr("readonly");
            txtEstateName.removeClass("checkError").next("span[class=wrong]").remove();
        });


        //栋座信息
        txtBuildingName.change(function () {
            hidBuildingKeyId.val("");
            //btnNextOperate.removeClass("btn-red").addClass("btn-gray").attr("disabled", "disabled");
           // $(this).next("span[class=wrong]").remove();
            //if ($(this).next("span[class=wrong]").length <= 0 && !hidBuildingKeyId.val() && $(this).val()) {
            //    //$(this).addClass("checkError").after('<span class="wrong">栋座单元:必须从智能提示选中！</span>');
            //    $(this).addClass("checkError").after(agencyVerify.greatErrorHtml($(this), '栋座单元:必须从智能提示选中！'));

            //}

            //联动房间信息
            txtHouseNo.val("");
            hidHouseKeyId.val("");
            if (txtBuildingName.val()) {
                txtHouseNo.removeAttr("readonly").removeClass("checkError").next("span[class=wrong]").remove();
            } else {
                txtHouseNo.attr("readonly", "readonly");
            }
            //txtHouseNo.attr("disabled", "disabled").removeClass("checkError").next("span[class=wrong]").remove();

        });

        txtBuildingName.focus(function () {
            if (txtEstateName.val()) {
                txtBuildingName.removeAttr("readonly").removeClass("checkError").next("span[class=wrong]").remove();
            } else {
                txtBuildingName.attr("readonly", "readonly");
            }
        });
        txtBuildingName.autocomplete(function () {
            if (txtEstateName.val()) {
                //return "/estate/auto-match-building-brief-for-recycle-bin?BuildingName=" + escape(txtBuildingName.val()) + '&EstateName=' + escape(txtEstateName.val());// + "&BuildingTypeCode=10"
                return "/estate/building-for-estate-obatin-ajax?EstateName=" + escape(txtEstateName.val()) + '&BuildName=' + escape(txtBuildingName.val());
            }
            return '';
        }, {
            width: 260,
            max: 1000,
            cacheLength: 0,
            selectFirst: false,
            minChars:0,
            clickMode: true,
            formatItem: function (row) {
                return row.BuildingName;
            },
            formatResult: function (row) {
                return row.BuildingName;
            }
        }).result(function (a, b) {
            hidBuildingKeyId.val(b.KeyId);
           // if (!b.IsBanAdd) {
                //hidBuildingKeyId.val(b.KeyId);
            txtHouseNo.removeAttr("readonly");
               // txtBuildingName.removeClass("checkError").next("span[class=wrong]").remove();
                txtHouseNo.removeClass("checkError").next("span[class=wrong]").remove();
            //}

        });


        //房间信息
        txtHouseNo.focus(function () {
            if (txtBuildingName.val()) {
                txtHouseNo.removeAttr("readonly").removeClass("checkError").next("span[class=wrong]").remove();
            } else {
                txtHouseNo.attr("readonly", "readonly");
            }
           // txtHouseNo.removeClass("checkError").next("span[class=wrong]").remove();
        });
        txtHouseNo.change(function () {
            hidHouseKeyId.val("");
            txtHouseNo.removeClass("checkError").next("span[class=wrong]").remove();
            //txtFloorVal.val("").removeClass("checkError").next("span[class=wrong]").remove();
            //if (txtHouseNo.val() && txtEstateName.attr("isstart") == "true") {

            //} else {
            //    btnNextOperate.attr("disabled", "disabled").attr("class", "btn-gray");
            //}
        });
        //自动完成房间填充
        txtHouseNo.autocomplete(function () {
            return "/estate/auto-match-house-no-for-recycle-bin?BuildingKeyId=" + hidBuildingKeyId.val() + "&EstateKeyId=" + hidEstateKeyId.val();
        }, {
            width: 260,
            max: 12,
            cacheLength: 0,
            selectFirst: false,
            minChars: 0,
            clickMode: true,
            formatItem: function (row) {
                return row.ItemText;
            },
            formatResult: function (row) {
                return row.ItemText;
            }
        }).result(function (a, b) {
            hidHouseKeyId.val(b.ItemValue);
           // if (hidHouseKeyId.val() == "") {
                //txtHouseNo.addClass("checkError").after(agencyVerify.greatErrorHtml(txtHouseNo, '没有删除的房号！'));
           // }

           // txtHouseNo.blur();
        });

        //txtHouseNo.focus(function () {
        //    $.ajax({
        //        url: "/estate/auto-match-house-no-for-recycle-bin?BuildingKeyId=" + hidBuildingKeyId.val() + "&EstateKeyId=" + hidEstateKeyId.val(),
        //        type: "POST",
        //        dataType: "json",
        //        success: function (data) {
        //            if (data.length <= 0) {
        //                txtHouseNo.val("");
        //                txtHouseNo.addClass("checkError").after(agencyVerify.greatErrorHtml(txtHouseNo, '没有删除的房号！'));
        //            }
        //            else {
        //                txtHouseNo.removeClass("checkError").next("span[class=wrong]").remove();
        //            }
        //        }
        //    });
            
        //});
    }
});

